//
//  QQNetworkObjectProtocol.h
//  QQNetworkEngine
//
//  Created by elvisgao on 2020/2/27.
//  Copyright © 2018 tencent. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "QQNetworkCodecDelegate.h"
#import "QQNetworkChannelDelegate.h"
#import "QQNetworkCommonDelegate.h"
#import "QQNetworkEventDelegate.h"

NS_ASSUME_NONNULL_BEGIN

@class QQOTSpan;

typedef NSString *QQNetworkEngineEventName;

/// 发送请求前
OBJC_EXTERN QQNetworkEngineEventName const QQNetworkEngineWillSendRequestEvent;

/// 发送请求完成
OBJC_EXTERN QQNetworkEngineEventName const QQNetworkEngineDidSendRequestEvent;

/// 接受到响应
OBJC_EXTERN QQNetworkEngineEventName const QQNetworkEngineDidRecvResponseEvent;



typedef void(^QQNetworkEngineEventDispatcher)(NSString *eventName, NSDictionary * _Nullable data);



/// 可以被QQNetworkEngine处理的请求对象必须符合的协议
@protocol QQNetworkObjectProtocol <NSObject>

/**
 * @brief 由QQNetworkEngine在发送时生成的请求序号，避免串包
 */
@property (nonatomic, assign) int seq;

/**
 * @brief 请求的超时时间，单位s
 */
@property (nonatomic, assign) int timeout;

/**
 * @brief 由QQNetworkEngine在发送时生成的请求traceid，会附带在请求包头中，后台可以用traceId搭建全链路监控
 */
@property (nonatomic, strong) NSString *traceId;

/**
 * @brief 业务命令字
 */
@property (nonatomic, strong) NSString *command;

/**
 * @brief 业务回包的pb类型
 */
@property (nonatomic) Class responseClass;

/**
 * @brief 业务可以指定请求结果回调时的队列，默认是主队列
 */
@property (nonatomic, strong) dispatch_queue_t responseQueue;

/// 追踪当前请求的span事件（QQOpenTelemetry概念），通过QQNetworkEngine发送时填充
@property (nonatomic, strong) QQOTSpan *span;

/// 传入一个block，接受QQNetworkEngine体系下的通知。
///
/// 除了QQNetworkEngine本身会抛出一些事件，codecDelegate、channelDelegate实现也可以通过这个block将相关事件抛给业务处理
@property (nonatomic, copy) QQNetworkEngineEventDispatcher eventDispatcher;

/**
 * @brief 公共delegate
 */
@property (nonatomic, weak) id <QQNetworkCommonDelegate> commonDelegate;

/**
 * @brief 打解包
 */
@property (nonatomic, weak) id <QQNetworkCodecDelegate> codecDelegate;

/**
 * @brief 发送数据通道
 */
@property (nonatomic, weak) id <QQNetworkChannelDelegate> channelDelegate;

/**
 * @brief 用于处理QQNetworkEngine相关的事件通知。已废弃，请用 eventDispatcher
 */
@property (nonatomic, weak) id <QQNetworkEventDelegate> eventDelegate DEPRECATED_ATTRIBUTE;

@end

NS_ASSUME_NONNULL_END
